package com.government.common.utils;

import cn.hutool.system.SystemUtil;

import java.text.DecimalFormat;
import java.util.Objects;
import java.util.StringJoiner;


public class StringUtil {

    public static final String EMPTY_STRING = "";
    public static final String NEWLINE = SystemUtil.get("line.separator", "\n");
    public static final String DOUBLE_QUOTE = "\"";
    public static final String COMMA = ",";
    public static final String WORD_O = "o";
    public static final String Ton = "、";
    public static final String MIDDLE_SHORT_LINE = "-";
    public static final String ZERO_FORMAT_SUB_ORDER = "00";
    public static final String ZERO_FORMAT = "000";
    public static final String ZERO_FORMAT_CONTRACT_NO = "0000";
    public static final String ZERO_FORMAT_APP_ORDER_NO = "#####";
    public static final String ZERO_FORMAT_JOURNEY_ME_ORDER_NO = "000000000";
    public static final String ELEVEN_ZERO = "00000000000";

    /**
     * 功能描述: <br>
     * 输入-->StringUtil.join(",", orderIds)
     * 输出-->orderId1,orderId2,orderId3
     *
     */
    public static String simpleJoin(CharSequence delimiter,
                                    Iterable<? extends CharSequence> elements) {
        Objects.requireNonNull(delimiter);
        Objects.requireNonNull(elements);
        StringJoiner joiner = new StringJoiner(delimiter);
        for (CharSequence cs : elements) {
            joiner.add(cs);
        }
        return joiner.toString();
    }

    /**
     * 功能描述: <br>
     * 输入-->StringUtil.join(",", orderIds)
     * 输出-->('orderId1', 'orderId2', 'orderId3')
     *
     */
    public static String join(CharSequence delimiter,
                              Iterable<? extends CharSequence> elements) {
        Objects.requireNonNull(delimiter);
        Objects.requireNonNull(elements);
        StringJoiner joiner = new StringJoiner(delimiter, "(", ")");
        for (CharSequence cs : elements) {
            joiner.add("'" + cs + "'");
        }
        return joiner.toString();
    }

    /**
     * 功能描述: <br>
     * 默认分隔符是逗号
     * 输入-->StringUtil.join(",", orderIds)
     * 输出-->('orderId1', 'orderId2', 'orderId3')
     *
     */
    public static String join(Iterable<? extends CharSequence> elements) {
        return join(",", elements);
    }

    public static String formatToSequence(long count) {
        return formatToSequence(count, ZERO_FORMAT);
    }

    public static String formatToSequence(long count, String pattern) {
        return new DecimalFormat(pattern).format(count);
    }

    /**
       * 功能描述: <br>
       * 〈手机号掩码处理〉
       *
       * @param
       *
       * @return:
       * @throws:
       * @Version: 1.0.0
       * @Author: 彭春雷
       * @Date: 9:05 2020/2/27
       */
    public static String hiddenNumber(String phone){
        return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    }
}
